package com.moorror.codegenvel.common.tree.enums;

import com.intellij.icons.AllIcons;
import com.moorror.codegenvel.utils.GuiUtils;
import lombok.Getter;

import javax.swing.*;

/**
 * @Author jiyanghuang
 * @Date 2022/8/8 23:26
 */
public enum MethodType {

    INTERFACE_METHOD(0, "接口方法", AllIcons.Nodes.Interface, GuiUtils.INTERFACE_NOTE),
    ABSTRACT_METHOD(1, "抽象类方法", AllIcons.Nodes.AbstractClass, GuiUtils.ABSTRACT_CLASS_NOTE),
    NORMAL_METHOD(2, "普通类方法", AllIcons.Nodes.Class, GuiUtils.CLASS_NOTE),
    ANONYMOUS_CLASS_METHOD(3, "匿名类方法", AllIcons.Nodes.AnonymousClass, GuiUtils.ANONYMOUS_CLASS_NOTE),
    RECURSIVE_METHOD(4, "递归调用方法", AllIcons.Gutter.RecursiveMethod, GuiUtils.RECURSIVE_METHOD_NOTE),
    LAMBDA_METHOD(5, "Lambda方法", AllIcons.Nodes.Lambda, GuiUtils.LAMBDA_NOTE),
    EXTEND_METHOD(6, "继承方法", GuiUtils.EXTEND_METHOD, GuiUtils.EXTEND_METHOD_NOTE),
    ASYNC_START(7, "异步开始方法", GuiUtils.RT_ASYNC, GuiUtils.RT_ASYNC_NOTE),
    PROXY_METHOD(8, "代理方法", GuiUtils.RT_PROXY, GuiUtils.RT_PROXY_NOTE),
    ;

    @Getter
    private int type;
    private String desc;
    private Icon icon;
    private Icon noteIcon;

    MethodType(int type, String desc, Icon icon, Icon noteIcon) {
        this.type = type;
        this.desc = desc;
        this.icon = icon;
        this.noteIcon = noteIcon;
    }

    public static MethodType value(int type) {
        for (MethodType methodType : values()) {
            if (methodType.type == type) {
                return methodType;
            }
        }
        return MethodType.NORMAL_METHOD;
    }

    public static Icon typeIcon(int type) {
        return value(type).icon;
    }

    public static Icon findCheck(MethodType methodType, boolean note) {
        if (note) {
            return methodType.noteIcon;
        }
        return methodType.icon;
    }
}
